/*package org.domain.pseample.session;

import java.io.IOException;

import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;

import org.apache.log4j.Logger;
import org.mobicents.mscontrol.MsConnection;
import org.mobicents.mscontrol.MsConnectionEvent;
import org.mobicents.mscontrol.MsConnectionListener;
import org.mobicents.mscontrol.MsEndpoint;
import org.mobicents.mscontrol.MsLink;

import org.mobicents.mscontrol.MsLinkMode;
import org.mobicents.mscontrol.MsSession;

@SuppressWarnings("serial")
public class MediaConnectionListener implements MsConnectionListener {
	private MapInstance mapInstance;
	//public static final String IVR_JNDI_NAME = "media/trunk/Conference/1";
	
    MediaConnectionListener(MapInstance mapInstance)
	{
		this.mapInstance = mapInstance;
	}

	private static Logger logger = Logger
			.getLogger(MediaConnectionListener.class);

	private SipServletRequest inviteRequest;

	public void connectionCreated(MsConnectionEvent event) {
		logger.info("connection created " + event);
	}

	public void connectionInitialized(MsConnectionEvent arg0) {
		logger.info("connection initialized " + arg0);
	}

	public void connectionDisconnected(MsConnectionEvent arg0) {
		logger.info("connection disconnected " + arg0);
	}

	public void connectionFailed(MsConnectionEvent arg0) {
		logger.error("connection failed " + arg0);
		try {
			inviteRequest.createResponse(
					SipServletResponse.SC_SERVER_INTERNAL_ERROR).send();
		} catch (IOException e) {
			logger.error("Exception in sending the error response", e);
		}

	}

	public void connectionHalfOpen(MsConnectionEvent arg0) {
		logger.info("connection half opened" + arg0);
	}

	public void connectionOpen(MsConnectionEvent event) {

		logger.info("connection open request" + event);
		final MsConnection msconnection = event.getConnection();
		MsEndpoint msendpoint = msconnection.getEndpoint();
		final MsSession mssession = msconnection.getSession();
		final MsLink mslink = mssession.createLink(MsLinkMode.FULL_DUPLEX);
		
		logger.info("setting mslink in mapinstance");
		mapInstance.setMsLink(mslink);
		
		inviteRequest.getSession().setAttribute("mslink", mslink);
		mslink.addLinkListener(new MsLinkListener() {
			public void linkCreated(MsLinkEvent linkEvent) {
				logger.info("PR-IVR link created " + linkEvent);

			}

			public void linkConnected(MsLinkEvent linkEvent) {
				logger.info("link connected "
						+ mslink.getEndpoints()[0].getLocalName() + " "
						+ mslink.getEndpoints()[1].getLocalName());
				// mslink.getEndpoints()[0].execute();
			}

			public void linkDisconnected(MsLinkEvent arg0) {
				// TODO Auto-generated method stub

			}

			public void linkFailed(MsLinkEvent arg0) {
				logger.info("link failed");

			}

			public void modeFullDuplex(MsLinkEvent arg0) {
				// TODO Auto-generated method stub

			}

			public void modeHalfDuplex(MsLinkEvent arg0) {
				// TODO Auto-generated method stub

			}
		});
		
		
		logger.info("sendin OKies to caller");

		logger.info("linking " + msendpoint.getLocalName() + "to IVR");
		//mslink.join(IVR_JNDI_NAME, msendpoint.getLocalName());
		
		

		String sdp = event.getConnection().getLocalDescriptor();
		logger.info("common abhina jauhri: " + msconnection.getEndpoint());
		SipServletResponse sipServletResponse = inviteRequest
				.createResponse(SipServletResponse.SC_OK);
		try {
			sipServletResponse.setContent(sdp, "application/sdp");
			sipServletResponse.send();
		} catch (Exception e) {
			logger.error(e);
		}

		
		 * provider = ConferenceCenter.getInstance().getProvider(); MsConnection
		 * msconnection = event.getConnection(); MsEndpoint msendpoint =
		 * msconnection.getEndpoint(); MsSession mssession =
		 * msconnection.getSession();
		 

	}

	public SipServletRequest getInviteRequest() {
		return inviteRequest;

	}

	public void setInviteRequest(SipServletRequest inviteRequest) {
		this.inviteRequest = inviteRequest;
	}

	public void connectionModeRecvOnly(MsConnectionEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void connectionModeSendOnly(MsConnectionEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void connectionModeSendRecv(MsConnectionEvent arg0) {
		// TODO Auto-generated method stub

	}

}
*/